﻿using System.Xml.Serialization;
using Alex.HydroDynLib.Enums;

namespace Alex.HydroDynLib.Measures
{
    [XmlRoot("Velocity")]
    public class Velocity : MeasureBase
    {
        #region Construct

        public Velocity()
        {
            value = 0;
        }

        public Velocity(double val)
        {
            value = val;
        }

        public Velocity(double val, Enums.Velocity mes)
        {
            value = 0;
            this[mes] = val;
        }

        public Velocity(Velocity vel)
        {
            value = vel.value;
        }

        #endregion

        public double this [Enums.Velocity index]        
        {
            get 
            {
                switch (index)
                {
                    case Enums.Velocity.MeterPerSecond:
                        return value;
                    case Enums.Velocity.KilometerPerHour:
                        return value*Constants.Hour/Constants.Kilometer;
                    case Enums.Velocity.Knots:
                        return value*Constants.Hour/Constants.NMile;
                    default:
                        return 0;
                }
            }
            set 
            {
                switch (index)
                {
                    case Enums.Velocity.MeterPerSecond:
                        this.value = value;
                        break;
                    case Enums.Velocity.KilometerPerHour:
                        this.value = value*Constants.Kilometer/Constants.Hour;
                        break;
                    case Enums.Velocity.Knots:
                        this.value = value*Constants.NMile/Constants.Hour;
                        break;
                    default:
                        break;
                }
            }
        }

        [XmlElement("Value")]
        public override double Value
        {
            get { return value; }
            set { this.value = value; }
        }

        public override string Measure
        {
            get { return "m/sec"; }
        }

        public override string ToString()
        {
            return Value.ToString() + " " + Measure;
        }
    }
}
